package com.yyk.yiliao.ui.activity.dingdan.activity;

import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.androidkun.xtablayout.XTabLayout;
import com.yyk.yiliao.R;
import com.yyk.yiliao.base.BaseActivity;
import com.yyk.yiliao.adapter.MyPagerAdapter;
import com.yyk.yiliao.ui.activity.dingdan.fragment.Tab_Five_Fragment;
import com.yyk.yiliao.ui.activity.dingdan.fragment.Tab_Four_Fragment;
import com.yyk.yiliao.ui.activity.dingdan.fragment.Tab_One_Fragment;
import com.yyk.yiliao.ui.activity.dingdan.fragment.Tab_Three_Fragment;
import com.yyk.yiliao.ui.activity.dingdan.fragment.Tab_Two_Fragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * 商品订单
 */
public class CommodityOrde_Activity extends BaseActivity implements XTabLayout.OnTabSelectedListener, ViewPager.OnPageChangeListener {

    @BindView(R.id.tablyout)
    XTabLayout tablyout;
    @BindView(R.id.vp)
    ViewPager vp;

    private List<String> datas = new ArrayList<>();
    private List<Fragment> fragments = new ArrayList<>();
    private MyPagerAdapter adapter;


    @Override
    public int getLayoutId() {
        return R.layout.activity_commodity_orde;
    }

    @Override
    public void initView() {
        initToolbar();
        initViews();
    }

    private void initToolbar() {
        setBackArrow();
        setTitle("商品订单");
    }

    @Override
    public void initData() {
        initDatas();
    }


    private void initDatas() {
        datas.add("全部");
        datas.add("待付款");
        datas.add("待收货");
        datas.add("已完成");
        datas.add("已取消");
    }


    private void initViews() {
        //循环注入标签
        for (String tab : datas) {
            tablyout.addTab(tablyout.newTab().setText(tab));
        }
        fragments.add(Tab_One_Fragment.newInstance(1));
        fragments.add(Tab_Two_Fragment.newInstance(2));
        fragments.add(Tab_Three_Fragment.newInstance(3));
        fragments.add(Tab_Four_Fragment.newInstance(4));
        fragments.add(Tab_Five_Fragment.newInstance(5));
        //设置TabLayout点击事件
        tablyout.addOnTabSelectedListener(this);
        vp.setOnPageChangeListener(this);
        adapter = new MyPagerAdapter(getSupportFragmentManager(), datas, fragments);
        vp.setAdapter(adapter);
        tablyout.setupWithViewPager(vp);


    }

    @Override
    public void onPointerCaptureChanged(boolean hasCapture) {
    }

    @Override
    public void onTabSelected(XTabLayout.Tab tab) {
        vp.setCurrentItem(tab.getPosition());

    }

    @Override
    public void onTabUnselected(XTabLayout.Tab tab) {

    }

    @Override
    public void onTabReselected(XTabLayout.Tab tab) {

    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {
        vp.setCurrentItem(position);
    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }


}
